<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        .box{
            width: 800px;
            height: 500px;
            background-color: skyblue;
            margin: 0 auto;
            
        }
        .hh{
            font-size: 30px;
            text-align: center;
            line-height: 350px;
        }
        .btn1{
            width: 100px;
            height: 50px;
            border-radius: 90%;
            border: none;
            margin-left: 350px;
        }
        .btn2{
            width: 100px;
            height: 50px;
            border-radius: 90%;
            border: none;
            margin-left: 350px;
            display: none;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="hh">点击抽取姓名</div>
        <button class="btn1">开始匹配</button>
        <button class="btn2 ">成功匹配</button>
    </div>
    <p></p>

    <script>
        let box = document.querySelector('.box');
        let hh = document.querySelector('.hh');
        let btn1 = document.querySelector('.btn1');
        let btn2 = document.querySelector('.btn2');
        let p = document.querySelector('p');
        let data = ["同学1","同学2","同学3","同学4","同学5","同学6","同学7","同学8","同学9"];
        let newdate = [];
        let num =0;
        let timer

        btn1.addEventListener('click',()=>{
            timer = setInterval(function(){
                hh.innerText = data[Math.floor(Math.random()*data.length)];
                    
            },10)
            btn1.style.display = 'none';
            btn2.style.display = 'block';
        })
        btn2.addEventListener('click',()=>{
            clearInterval(timer);
            newdate.push(hh.innerText);
            data.splice(data.indexOf(hh.innerText),1) ;
            p.innerText = newdate;
            btn1.style.display = 'block';
            btn2.style.display = 'none';
            if(data.length <= 0){
                hh.innerText = '别抽了，再抽就要抽干了！'
                btn1.setAttribute('disabled','true')
            
            }
        })
    </script>
    
    
</body>
</html>